﻿using System;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace Livraria
{
    public partial class AdicionarProduto : System.Web.UI.Page
    {
        SqlConnection conn;
        //protected string strConnectionString = @"Data Source=srv-acd-sql;Initial Catalog=bdAsp_lucas;Integrated Security=True";
        protected string strConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + "C:\\Arquivos de programas\\Microsoft SQL Server\\MSSQL.1\\MSSQL\\Data\\bdAsp_Livraria.mdf" + ";Integrated Security=True;Connect Timeout=30;User Instance=True";

        protected void Page_Load(object sender, EventArgs e) 
        {
            
        }

        protected void btn_ok_Click(object sender, EventArgs e)
        {            
            conn = new SqlConnection(strConnectionString);

            string nome = txt_nome.Text;
            string categoria = ddl_categoria.SelectedItem.Value.ToString();

            string sqlInsert = "insert into Produtos (nome, categoria) values ('" + nome + "','" + categoria + "');";

            SqlCommand cmd = new SqlCommand(sqlInsert, conn);            
            cmd.Connection.Open();
            cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            Limpar();
        }

        protected void btn_limpar_Click(object sender, EventArgs e)
        {
            Limpar();
        }

        protected void Limpar()
        {
            txt_nome.Text = "";
            ddl_categoria.SelectedItem.Text = "";
        }
    }
}